package cst.a113cx.fragmentrecyclerview;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import Adapter.AdapterFor_RecyclerView;
import Bean.ArticleBean;
import Retorfit对象.ArticleModel;
import retrofit2.Call;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyFragment04 extends Fragment {
    private  View view;
    private Context context=getContext();
    private TextView textView01;
    private RecyclerView recyclerView;

    List<ArticleBean> list;
    AdapterFor_RecyclerView adapterFor_recyclerView;


    public MyFragment04() {
        // Required empty public constructor
    }
    void initRecyclerView(){
        recyclerView=(RecyclerView)view.findViewById(R.id.recyclerview04);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        adapterFor_recyclerView=new AdapterFor_RecyclerView(context);
        adapterFor_recyclerView.setList(list);
        recyclerView.setAdapter(adapterFor_recyclerView);

    }
    void getRecyclerViewFromInternet() {
        ArticleModel AM = new ArticleModel() {


            @Override
            public void ArticleonResponse(Call<List<ArticleBean>> call, Response<List<ArticleBean>> response) {
                if (response.isSuccessful() && response.body() != null) {

                    adapterFor_recyclerView.setList(response.body());


                }

            }

            @Override
            public void ArticleonFailure(Call<List<ArticleBean>> call, Throwable t) {
                Toast.makeText(context, "fail", Toast.LENGTH_SHORT).show();
            }
        };
        AM.MakeAAsk("project",1,"2ts2j910hv4m270hipde4a67d7");


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        context=getContext();
        view=inflater.inflate(R.layout.layout04,container,false);
        initRecyclerView();
        textView01=(TextView)view.findViewById(R.id.textView04);
        textView01.setText("项目");
        textView01.setGravity(1);
        getRecyclerViewFromInternet();
        //Toast.makeText(context, "加载项目", Toast.LENGTH_SHORT).show();
        return view;
    }

}
